package cn.dt70.service.impl;

import cn.dt70.dao.aqbInterestandcode.AqbInterestandcodeMapper;
import cn.dt70.pojo.AqbInterestandcode;
import cn.dt70.service.AqbInterestandcodeService;
import cn.dt70.utils.Constants;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("AqbInterestandcodeService")
public class AqbInterestandcodeServiceImpl implements AqbInterestandcodeService {

    private static final Logger LOGGER = Logger.getLogger(AqbInterestandcodeServiceImpl.class);

    @Resource
    private AqbInterestandcodeMapper aqbInterestandcodeMapper;

    @Override
    public boolean createCode(int userId) {
        boolean flag = false;
        int id = (int)(Math.random()*5+1);
        String jxm = Constants.getUUID(6);
        try {
            int row = aqbInterestandcodeMapper.createCode(id,jxm,Integer.valueOf(userId));
            if(row == 1){
                flag = true;
                LOGGER.debug("AqbInterestandcodeServiceImpl.createCode 方法插入成功");
            }else{
                LOGGER.debug("AqbInterestandcodeServiceImpl.createCode 方法插入失败");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AqbInterestandcodeServiceImpl.createCode 方法异常"+e.getMessage());
        }
        return flag;
    }

    @Override
    public boolean updateStatus(String jxm) {
        boolean flag = false;
        try {
            int row = aqbInterestandcodeMapper.updateStatus(jxm);
            if(row == 1){
                flag = true;
                LOGGER.debug("AqbInterestandcodeServiceImpl.updateStatus 方法修改成功");
            }else{
                LOGGER.debug("AqbInterestandcodeServiceImpl.updateStatus 方法修改失败");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AqbInterestandcodeServiceImpl.updateStatus 方法异常"+e.getMessage());
        }
        return flag;
    }

    @Override
    public AqbInterestandcode getJxj(String jxm) {
        AqbInterestandcode aqbInterestandcode = null;
        try {
            aqbInterestandcode = aqbInterestandcodeMapper.getJxj(jxm);
            if(null == aqbInterestandcode){
                LOGGER.debug("AqbInterestandcodeServiceImpl.getJxj 方法查询失败");
                aqbInterestandcode = new AqbInterestandcode();
            }else {
                LOGGER.debug("AqbInterestandcodeServiceImpl.getJxj 方法查询成功");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AqbInterestandcodeServiceImpl.getJxj 方法异常"+e.getMessage());
            aqbInterestandcode = new AqbInterestandcode();
        }
        return aqbInterestandcode;
    }

    @Override
    public AqbInterestandcode getJxByUserId(int userId) {
        AqbInterestandcode aqbInterestandcode = null;
        try {
            aqbInterestandcode = aqbInterestandcodeMapper.getJxByUserId(userId);
            if(null == aqbInterestandcode){
                LOGGER.debug("AqbInterestandcodeServiceImpl.getJxByUserId 方法查询失败");
                aqbInterestandcode = new AqbInterestandcode();
            }else {
                LOGGER.debug("AqbInterestandcodeServiceImpl.getJxByUserId 方法查询成功");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            LOGGER.error("AqbInterestandcodeServiceImpl.getJxByUserId 方法异常"+e.getMessage());
            aqbInterestandcode = new AqbInterestandcode();
        }
        return aqbInterestandcode;
    }
}
